#include <iostream>
using namespace std;

class Point
{
public:
    // 使用带参数默认构造函数，并使用初始化列表初始化 x，y
    Point(double x = 0, double y = 0) : x(x), y(y) {
        //cout << "Point(double x = 0, double y = 0)" << endl;
        cout << "Point(double x = " << x << ", double y = " << y << ")" << endl;
    }
    // 拷贝构造函数
    Point(const Point & p) {
        //cout << "Point(const Point &p)" << endl;
        // 打印点的值
        cout << "Point(const Point &p:(" << p.x << ", " << p.y << ")" << endl;
        this->x = p.x;
        this->y = p.y;
    }
    // 析构函数，由于没有申请内存，析构函数中不需要做什么
    ~Point() {
        //cout << "~Point()" << endl;
        cout << "~Point():(" << x << ", " << y << ")" << endl;
    }
    // x, y 绑定的成员函数
    void setPoint(const Point &p) {
        this->x = p.x;
        this->y = p.y;
    }
    void setPoint(double x, double y) {
        this->x = x;
        this->y = y;
    }
    void setX(double x) { this->x = x; }
    void setY(double y) { this->y = y; }
    double getX() { return x; }
    double getY() { return y; }
private:
    double x;
    double y;
};

class Line
{
public:
    // 构造函数
    Line(const Point & pA, const Point &pB)
        : pointA(new Point(pA))
        , pointB(new Point(pB)) {
        cout << "Line(const Point & pA, const Point &pB)" << endl;
    }
    Line(double aX, double aY, double bX, double bY)
        : pointA(new Point(aX, aY))
        , pointB(new Point(bX, bY)) {
        cout << "Line(double aX, double aY, double bX, double bY)" << endl;
    }
    // 析构函数
    ~Line() {
        delete pointA;
        pointA = nullptr;
        delete pointB;
        pointB = nullptr;
        cout << "~Line()" << endl;
    }
    // 数据成员操作函数
    void setPointA(const Point & pA) {
        pointA->setPoint(pA);
    }
    void setPointB(const Point & pB) {
        pointB->setPoint(pB);
    }
    void setPoint(const Point & pA, const Point & pB) {
        pointA->setPoint(pA);
        pointB->setPoint(pB);
    }
    Point *getPointA() { return pointA; }
    Point *getPointB() { return pointB; }
private:
    Point *pointA;
    Point *pointB;
};

void stackInstantiation()
{
    Line line(1, 2, 3, 4);
}

int main()
{
    stackInstantiation();
    return 0;
}